/*
 * Copyright 2008-2023 dexian.vip. All rights reserved.
 * Support: http://www.dexian.vip
 * License: http://www.dexian.vip/license
 */

package vip.dexian.core.base.command;

import vip.dexian.common.utils.NumberUtils;
import vip.dexian.core.base.validation.group.Update;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serial;
import java.io.Serializable;

/**
 * 基础请求指令，主要用于保存、更新、删除操作
 *
 * @author 挺好的 2023年05月30日 19:19
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@SuperBuilder
public abstract class BaseCommand implements Serializable {

    @Serial
    private static final long serialVersionUID = 8081820306794185836L;

    /**
     * 实体类ID
     */
    @NotNull (message = "ID不能为空", groups = Update.class)
    @Positive (message = "ID只能为大于0的整数", groups = Update.class)
    private Long id;

    /**
     * 是否传递了ID
     *
     * @return 仅当根据id更新的时候，才可传递ID
     */
    public boolean isNew () {
        return !NumberUtils.isPositive(this.id);
    }

}
